/**
 * Created with IntelliJ IDEA.
 * User: duoba
 * Date: 16/3/2
 * Time: 上午10:48
 * To change this template use File | Settings | File Templates.
 */

package com.cake21.uitest.Page;

import com.cake21.uitest.Constant.Constants;
import com.cake21.uitest.System.Core.Page;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import java.util.List;

public class ShoppingCartPage extends Page {
    /*页面元素*/
    @FindBy(css = ".cart-item")
    private List<WebElement> cartItems;
    @FindBy(css = ".dialog-tips-content")
    private WebElement dialogContent;

    /*载入页面*/
    protected void load() {
        driver.get(Constants.ShoppingCartURL);
    }
    /*从购物车移除第一款蛋糕*/
    public int removeOneCake() {
        int cakeNumber = cartItems.size();
        if (cakeNumber > 0) {
            WebElement removeBtn = cartItems.get(0).findElement(By.className("btn-delete"));
            removeBtn.click();
            if (dialogContent.isDisplayed()) {
                dialogContent.findElement(By.cssSelector(".action-confirm")).click();
                return 1;
            } else {
                return 0;
            }
        } else {
            return 0;
        }
    }
}
